﻿Public Class Loglib
    ''' <summary>
    ''' 创建时间：2017/7/16
    ''' 说明：把日志内容写入到指定文件夹的文件名中。返回1=写入成功，0=写入失败     
    ''' </summary>
    ''' <param name="vFilepath">文件夹名</param>
    ''' <param name="vFileName">不带路径的文件名</param>
    ''' <param name="vStyle">操作类型</param>
    ''' <param name="vMod">操作模块</param>
    ''' <param name="vContent">日志内容。</param>
    ''' <returns>返回1=写入成功，0=写入失败</returns>
    ''' <remarks></remarks>
    Public Shared Function WriteLog(ByVal vFilepath As String, ByVal vFileName As String, ByVal vStyle As String, ByVal vMod As String, ByVal vContent As String) As Integer
        Dim datNow As String = CDate(Now).ToString("yyyy-MM-dd HH:mm:ss")
        Dim intsuc As Integer = 0
        Try
            Dim strPath As String = vFilepath
            If Not My.Computer.FileSystem.DirectoryExists(strPath) Then
                My.Computer.FileSystem.CreateDirectory(strPath)
            End If
            If Not My.Computer.FileSystem.FileExists(vFileName) Then
                My.Computer.FileSystem.WriteAllText(vFileName, String.Empty, False)
            End If
            Dim strValue As String = String.Empty
            strValue = "[" & datNow & "]   "
            strValue &= "操作类型:" & vStyle & "" & vbCrLf
            strValue &= vContent & vbCrLf
            My.Computer.FileSystem.WriteAllText(vFileName, strValue, True)
            intsuc = 1
        Catch ex As Exception
            intsuc = 0
        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 创建时间：2017/7/13
    ''' 说明：写日志  
    ''' </summary>
    ''' <param name="vStyle">操作类型</param>
    ''' <param name="vMod">模块名</param>
    ''' <param name="vContent">操作内容</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function WriteLog(ByVal vStyle As String, vMod As String, ByVal vContent As String) As Integer
        Dim intsuc As Integer = 0
        Dim vFileName As String
        Dim strPath As String = "d:\log"
        vFileName = strPath + "\" & Now.ToString("yyyyMMdd") & ".txt"
        Return WriteLog(strPath, vFileName, vStyle, vMod, vContent)

    End Function
End Class
